﻿/**
生产计划版块
Dai 2022-06-17
**/

/**
更改临时表数据
**/
function ChanageData(keyCode) {
    var table = layui.table;
    var data = table.cache["list"];
    var rsl = AddTempProduct(JSON.stringify(data), keyCode);
    if (rsl.Result) {
        var js = 0;
        for (var i = 0; i < data.length; i++) {
            if (data[i].number != "") {
                js += parseFloat(data[i].number);
            }
        }
        $("input[ name='number']").val(js);
    }
}

/**
删除临时表数据
**/
function DelData(proCode, plCode) {
    $.ajax({
        url: "../Plan/DelPlanTempData",
        data: { proCode: proCode, timekey: timeKey, plCode: plCode },
        dataType: "json",
        type: "POST",
        success: function (data) {
            if (!data.Result) {
                layer.msg(data.Message);
            }
        }
    });
}


/**
* 生产计划保存
* **/
var doView = "";
function savePlanData() {

    if (doView == "1") {
        layer.msg("对不起，当前页面状态无权限进行此操作"); return;
    }
    var url = "../Plan/AddProductPlan";
    var table = layui.table;
    var data = table.cache["list"];
    $.ajax({
        url: url,
        data: { mData: JSON.stringify(FormToJson("AddForm")), plCode: plCode, cData: JSON.stringify(data) },
        dataType: "json",
        type: "POST",
        success: function (data) {
            if (data.Result) {
                var id = $("input[ name='id']").val();

                layer.alert("信息保存成功", { icon: 6 }, function (index) {
                    // 获得frame索引
                    //var index = parent.layer.getFrameIndex(window.name);
                    ////关闭当前frame
                    //parent.layer.close(index);
                    layer.close(index);
                });

                setTimeout(closeWin, 2000);
            } else {
                layer.msg(data.Message);
            }
        }
    });
}


/**
 * 选择销售单据数据信息
 * @param {any} datas:数据内容
 */
function AddTempProduct(datas, keyCode) {
    var rsl = undefined;
    $.ajax({
        url: "../Plan/AddTempPlanProduct",
        //data: { datas: datas },
        data: { datas: datas, keyCode: keyCode },
        dataType: "json",
        type: "POST",
        async: false,
        success: function (data) {
            rsl = data;
        }
    });
    return rsl;
}

function GetTempData(keyCode,plType) {
    var rsl = undefined;
    $.ajax({
        url: "../Plan/loadTempProduct",
        data: { "keyCode": keyCode, plType: plType },
        dataType: "json",
        type: "POST",
        async: false,
        success: function (data) {
            rsl = data;
        }
    });
    return rsl;
}